import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-07-23
 * Time:18:47
 * Text：一百个线程加速
 */
public class Text6 {
    int balance =0;
    private final Lock lock = new ReentrantLock();
    public int get(){
        return balance;
    }
    public void incer(){
        //可以支持一百个线程给balance+1
        lock.lock();
        try{
            balance++;
        }finally {
            lock.unlock();
        }
    }
    public static void main(String[] args) {
        Text6 text6 = new Text6();
        for(int i=0; i < 100; i++){
            Thread thread =new Thread(()->{
                text6.incer();
            });
            thread.start();
        }

        try{
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
